package nrrg.zhujuxing.application.learnscala

import scala.annotation.tailrec

object recruison {
  def main(args: Array[String]): Unit = {
    def tailFactorial(n: Int): Int = {
      @tailrec
      def loop(n:Int, curRes:Int):Int = {
        if (n == 0) return curRes
        loop(n-1, curRes * n)
      }
      loop(n, 1)
    }

    println(tailFactorial(5))
  }

}
